package com.orangelife.mobile.point.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.common.jump.PointJumper;
import com.common.jump.TeHuiJumper;
import com.common.jump.WebJumper;
import com.common.sp.AppSp;
import com.curry.android.http.OrangeDataHandler;
import com.curry.android.http.OrangeErrorHandler;
import com.curry.android.http.VolleyHttpUtil;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.common.activity.OrangeLifeBaseActivity;
import com.orangelife.mobile.point.biz.MyPointBiz;
import com.orangelife.mobile.util.StringUtil;

import org.json.JSONObject;

import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 我的橙汁
 * <p/>
 * Create by yw 2016年5月6日 15:44:22.Modify by wgf on 16072201
 *
 * @author yw
 */

public class MyPointActivity extends OrangeLifeBaseActivity {

    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_title_right)
    TextView tvTitleRight;
    @Bind(R.id.tvJifen)
    TextView tvJifen;
    @Bind(R.id.tvTip)
    TextView tvTip;
    @Bind(R.id.tvQianDao)
    TextView tvQianDao;
    @Bind(R.id.tvShopping)
    TextView tvShopping;
    @Bind(R.id.tvGongFang)
    TextView tvGongFang;

    @Override
    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_my_score);
        ButterKnife.bind(this);
        initView();
        requestPoints();
    }

    /**
     * 初始化组件
     */
    private void initView() {
        tvTitle.setText("我的橙汁");
        tvTitleRight.setText("橙汁明细");
    }


    /**
     * 请求积分
     */
    private void requestPoints() {
        MyPointBiz.getMyPoints(new VolleyHttpUtil.ResponseCallBack() {
                                   @Override
                                   public void handleResponse(JSONObject response, int errCode) {
                                       if (OrangeErrorHandler.getInstance().isSuccess(response)) {
                                           Map<String, Object> map = OrangeDataHandler.getMapWithEntityNoGson(response);
                                           String validPoints = map.get("validPoints").toString();//有效积分
                                           String freezePoints = map.get("freezePoints").toString();//冻结积分
                                           if (StringUtil.isBlank(validPoints) || validPoints.equals("0")) {
                                               tvJifen.setVisibility(View.GONE);
                                               tvTip.setVisibility(View.VISIBLE);
                                           } else {
                                               tvJifen.setText(validPoints + "ml");
                                           }
                                       }
                                   }
                               }

        );
    }


    @OnClick({R.id.tv_title_right, R.id.tvQianDao, R.id.tvShopping, R.id.tvGongFang})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_title_right:
                PointJumper.jumpToPointDetail(this);
                break;
            case R.id.tvQianDao:
                WebJumper.jumpToSignIn(this, AppSp.isShowGuide());
                break;
            case R.id.tvShopping:
                TeHuiJumper.jumpToTehui(this);
                break;
            case R.id.tvGongFang:
                WebJumper.jumpToJifenGongFang(this);
                break;
        }
    }
}
